package com.open.fei.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.open.fei.service.impl.TestServiceImpl;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoYuFei
 */
@RestController
public class TestController {
    @Resource
    private TestServiceImpl testService;
    @GetMapping("/sentinel/test1")
    public void test1(){
       testService.getUserName();
    }
    @GetMapping("/sentinel/test2")
    public void test2(){
        testService.getUserName();
    }
    @GetMapping("/sentinel/test3")
    public void test3(){
        try {
            //暂停几秒钟线程
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) { e.printStackTrace();
        }
        System.out.println("testD 测试RT");

    }
    @GetMapping("/sentinel/test4")
    public void test4(){
        int x=1/0;
    }
    @GetMapping("/sentinel/test5")
    public void test5(){
        int x=1/0;
    }
    @GetMapping("/sentinel/test6")
    @SentinelResource(value = "test6",blockHandler = "blockHandler")
    public String test6(@RequestParam(value="p1",required =false)String p1,
                      @RequestParam(value = "p2",required = false) String p2){
        System.out.println("热点key值限流！");
        return "ok";
    }
    public String blockHandler(String p1, String p2, BlockException e) {
        return "请稍后再试!";
    }
}
